package com.qcby.front.controller;


import com.qcby.framwork.utils.ResponseResult;
import com.qcby.front.model.SgArticle;
import com.qcby.front.service.SgArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 文章表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2024-09-01
 */
@RestController
@RequestMapping("/article")
public class SgArticleController {
    @Autowired
    private SgArticleService sgArticleService;

    @GetMapping("/list")
    public List<SgArticle> test(){
        return sgArticleService.list();
    }

    /**
     * 热门文章
     * @return
     */
    @GetMapping("/hotArticleList")
    public ResponseResult hotArtcleList(){
        //查询热门文章
        ResponseResult responseResult=sgArticleService.hotArticleList();
        return responseResult;
    }
    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum,Integer pageSize,Long categoryId){
        return sgArticleService.articleList(pageNum, pageSize, categoryId);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable("id") Long id){
        return sgArticleService.getArticleDetail(id);
    }

    /**
     * 浏览次数
     * @param id
     * @return
     */
    @PutMapping("/updateViewCount/{id}")
    //游客也可以增加浏览量
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return sgArticleService.updateViewCount(id);
    }

}


